package com.study.ws.controller;

import com.study.ws.model.ps.entity.vo.PSMessageVO;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xl-9527
 * @since 2025/3/28
 **/
@RestController
@RequestMapping("/redis/ps")
public class SendMsgWIthRedisPSModeController {

    private final RedisTemplate<String, Object> redisTemplate;

    public SendMsgWIthRedisPSModeController(final RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    /**
     * 发送 redis 发布订阅消息
     *
     * @param psMessage 要发送的消息
     */
    @PostMapping("send")
    public ResponseEntity<?> sendMsg(@RequestBody PSMessageVO psMessage) {
        return ResponseEntity.ok(redisTemplate.convertAndSend("test", psMessage));
    }
}
